class Solution {
    public static int removeElement(int[] nums, int val) {
        int len = 0;
        int latter = 0, former = 0;
        while (former < nums.length) {
            while (former < nums.length && nums[former] == val) {
                former++;
            }
            if (former < nums.length) {
                nums[latter++] = nums[former++];
                len++;
            }
        }
        return len;
    }

    public int romanToInt(String s) {
        int num = 0;
        char[] ch = s.toCharArray();
        for (int i = 0; i < s.length(); i++) {
            if (ch[i] == 'I') {
                num += 1;
            } else if (ch[i] == 'V') {
                num += 5;
                if (i - 1 >= 0 && ch[i - 1] == 'I') {
                    num -= 2;
                }
            } else if (ch[i] == 'X') {
                num += 10;
                if (i - 1 >= 0 && ch[i - 1] == 'I') {
                    num -= 2;
                }
            } else if (ch[i] == 'L') {
                num += 50;
                if (i - 1 >= 0 && ch[i - 1] == 'X') {
                    num -= 20;
                }
            } else if (ch[i] == 'C') {
                num += 100;
                if (i - 1 >= 0 && ch[i - 1] == 'X') {
                    num -= 20;
                }
            } else if (ch[i] == 'D') {
                num += 500;
                if (i - 1 >= 0 && ch[i - 1] == 'C') {
                    num -= 200;
                }
            } else if (ch[i] == 'M') {
                num += 1000;
                if (i - 1 >= 0 && ch[i - 1] == 'C') {
                    num -= 200;
                }
            }
        }
        return num;
    }

    public static void main(String[] args) {
        removeElement(new int[]{3, 2, 2, 3}, 3);
    }
}